<template>
	<view class="zhgl">
		<headertop title="账户管理" str1="oridei"></headertop>
		<image src="https://jingwei.xunfuzhifuzaixian.com/static/images/Rectangle 2@2x.png" class="zhglback"
			mode="widthFix"></image>
		<view :style="{'margin-top':statusBarHeight+'px','height':barHeight+'px'}">

		</view>
		<view class="contentList">
			<view class="msgicon" v-if="!list.length">
				<image :src="_static('https://jingwei.xunfuzhifuzaixian.com/static/images/wxnone.png')" mode="widthFix">
				</image>
				<view class="msgtext">
					暂无内容
				</view>
			</view>
			<view class="itembox" v-for="(item,index) in list" :key="index" @click="gopage(item.id)">
				<view class="topline">
					<view class="ll">
						<image src="https://jingwei.xunfuzhifuzaixian.com/static/images/Frame@2x(12).png" mode="">
						</image>
						<span>{{item.bankname}}</span>
					</view>
					<view class="yhk">
						银行卡
					</view>
				</view>
				<view class="skrname">
					收款人名称：{{item['username']}}
				</view>
				<view class="bottomline">
					<view class="numm">
						{{item['cardnum']}}
					</view>
					<image src="https://jingwei.xunfuzhifuzaixian.com/static/images/Frame@2x(13).png" class="removeicon"
						mode="" @click.stop="remove(item)"></image>
				</view>
			</view>
		</view>
		<view style="height: 186rpx;">

		</view>
		<view class="fixedbox">
			<view class="addzhbtn" @click="gopage1()">
				添加账户
			</view>
		</view>
	</view>
</template>

<script setup>
	import headertop from '@/components/header.vue'
	import {
		ref,
		onMounted,
		reactive,
	} from 'vue'
	import {
		onLoad,
		onShow,
		onPageScroll,
		onReachBottom
	} from "@dcloudio/uni-app";
	import {
		_static
	} from '@/ulm/utils/url.js'
	import {
		$api
	} from '../../ulm';
	const statusBarHeight = ref('')
	const back1 = ref('')
	const barHeight = ref('')
	const total = ref(0)
	const typestr = ref('')
	const list = ref([])
	const query = reactive({
		page: 1,
		limit: 10
	})
	onMounted(() => {
		statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight
		const {
			top,
			height
		} = wx.getMenuButtonBoundingClientRect();
		barHeight.value = height ? height + (top - statusBarHeight.value) * 2 : 38;
	})
	onLoad((opt) => {
		typestr.value = opt.typestr
	})
	onReachBottom(() => {
		if (total.value > list.value.length) {
			query['page']++
			banklistinit()
		}
	})
	onPageScroll((e) => {
		if (e.scrollTop > 100) {
			back1.value = '#CAEEFF'
		} else {
			back1.value = ''
		}
	})
	onShow(() => {
		query['page'] = 1
		list.value = []
		banklistinit()
	})
	async function banklistinit() {
		const res = await $api.banklist(query)
		if (res.code == 1) {
			list.value.push(...res.data.list)
			total.value = res.data.count
		}
	}

	function gopage(id) {
		if (typestr.value == 'dz' && list.value.length) {
			uni.setStorageSync('zhId', id)
			uni.navigateBack()
			return
		}
		uni.navigateTo({
			url: '/sub_me/index/addzh?id=' + id
		})
	}

	function gopage1() {
		uni.navigateTo({
			url: '/sub_me/index/addzh'
		})
	}

	function remove(item) {
		uni.showModal({
			title: '提示', // 标题（可选）
			content: '是否要删除该数据？', // 内容（可选）
			confirmText: '确定', // 确认按钮文字（可选，默认“确定”）
			cancelText: '取消', // 取消按钮文字（可选，默认“取消”）
			success: (res) => {
				if (res.confirm) {
					sc(item)
					// 执行确定后的逻辑
				} else if (res.cancel) {
					// 执行取消后的逻辑
				}
			},
			fail: (err) => {
				console.error('弹窗调用失败', err);
			}
		});
	}

	async function sc(item) {
		const res = await $api.delbank({
			id: item.id
		})
		if (res.code == 1) {
			setTimeout(() => {
				uni.showToast({
					title: '删除成功',
					icon: 'none'
				})
			}, 500)

			query['page'] = 1
			list.value = []
			banklistinit()
		} else {
			uni.showToast({
				title: res.msg,
				icon: 'none'
			})
		}
	}
</script>

<style lang="scss">
	.msgicon {
		width: 608rpx;
		margin: 100rpx auto;
		overflow: hidden;

		.msgtext {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #86909C;
			text-align: center;
			width: 100%;
			margin-top: 30rpx;
		}

		image {
			width: 608rpx;
		}
	}

	page {
		background: #F7F8FA;
	}

	.fixedbox {
		width: 100%;
		height: 186rpx;
		background: #FFFFFF;
		box-shadow: 0rpx -4rpx 10rpx 0rpx rgba(0, 0, 0, 0.06);
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		position: fixed;
		bottom: 0%;
		display: flex;
		justify-content: center;

		.addzhbtn {
			width: 686rpx;
			height: 82rpx;
			background: #13A2E6;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
			text-align: center;
			line-height: 82rpx;
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			margin-top: 24rpx;
		}
	}

	.zhgl {
		width: 100%;
		overflow: hidden;
		position: relative;

		.zhglback {
			width: 100%;
			height: 486rpx;
			position: absolute;
			z-index: -1;
		}

		.contentList {
			width: 686rpx;
			margin: auto;
			margin-top: 32rpx;
			overflow: hidden;

			.itembox {
				width: 100%;
				height: 228rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(0, 0, 0, 0.05);
				border-radius: 24rpx 24rpx 24rpx 24rpx;
				overflow: hidden;
				margin-bottom: 28rpx;

				.skrname {
					width: 630rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #4E5969;
					margin: auto;
					margin-top: 20rpx;
				}

				.bottomline {
					width: 630rpx;
					margin: auto;
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 20rpx;

					.numm {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 32rpx;
						color: #1D2129;
					}

					.removeicon {
						width: 36rpx;
						height: 36rpx;
					}
				}

				.topline {
					width: 630rpx;
					height: 92rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin: auto;
					border-bottom: 2rpx solid #F2F3F5;

					.ll {
						display: flex;
						align-items: center;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 32rpx;
						color: #1D2129;

						image {
							width: 40rpx;
							height: 40rpx;
							margin-right: 12rpx;
						}
					}

					.yhk {
						width: 144rpx;
						height: 56rpx;
						background: #E8F3FF;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						text-align: center;
						line-height: 56rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 28rpx;
						color: #2AB4F5;
					}
				}
			}
		}
	}
</style>